<script setup>
import {
    User,
    SwitchButton,
    CaretBottom
} from '@element-plus/icons-vue'
import { ref } from 'vue'
const tableData = ref()
import { getAllCourseService } from '@/api/teacherApi/getAllCourseService.js'
const getCourseInfo = async () => {
    let result = await getAllCourseService();
    tableData.value = result;
}
getCourseInfo();
// do not use same name with ref
const form = ref({
    name: '',
    region: ''
})
import { ElMessage } from 'element-plus'
import { createClassService } from '@/api/teacherApi/createClassService.js'
const onSubmit = async () => {
    let result = await createClassService(form.value.name, form.value.region);
    if (result.code == 502) {
        ElMessage({
            message: '创建成功',
            type: 'success',
        })
    }
    else {
        ElMessage.error('创建失败')
    }
}
</script>
<template>
    <el-row type="flex" justify="center">
        <el-col :span="24" :sm="20" :md="16" :lg="12">
            <el-form :model="form" label-width="auto">
                <el-form-item label="课堂名称">
                    <el-input v-model="form.name" />
                </el-form-item>
                <el-form-item label="选择课程">
                    <el-select v-model="form.region" placeholder="请选择课程">
                        <el-option v-for="(course, index) in tableData" :key="index" :label="course.courseName"
                            :value="course.courseName" />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-row type="flex" justify="center">
                        <el-button type="primary" @click="onSubmit">Create</el-button>
                    </el-row>
                </el-form-item>
            </el-form>
        </el-col>
    </el-row>
</template>
